import 'package:flutter/services.dart';
import 'package:lib_core/viewmodel/base_change_notifier_model.dart';
import 'package:module_home/model/ISSDataEntity.dart';
import 'dart:convert';

import 'package:module_home/model/ScoreEntity.dart';

class IssPageModel extends BaseChangeNotifierModel {
  List<ScoreEntity> list = [];
  List<ISSDataEntity> issDataList = [];

  void loadData() async {
    String value = await loadAsset();
    Map countyMap = json.decode(value);
    List _list = countyMap['data'];
    List<ScoreEntity> scoreList =
        _list.map((model) => ScoreEntity.fromJson(model)).toList();
    this.list = scoreList;

    String issData = await loadISSFromAsset();
    Map issDataMap = json.decode(issData);
    List _dataList = issDataMap['data'];
    List<ISSDataEntity> dataList =
        _dataList.map((model) => ISSDataEntity.fromJson(model)).toList();
    this.issDataList = dataList;

    notifyListeners();
  }

  Future<String> loadAsset() async {
    return rootBundle.loadString('lib/res/score.json');
  }

  Future<String> loadISSFromAsset() async {
    return rootBundle.loadString('lib/res/menu.json');
  }
}
